//
//  ComicsListCell.m
//  SweetComics
//
//  Created by LeeZhe on 15/2/2.
//  Copyright (c) 2015年 LeeZhe. All rights reserved.
//

#import "ComicsListCell.h"
#import "UIImageView+WebCache.h"
@implementation ComicsListCell

- (void)awakeFromNib {
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.title = [[UILabel alloc] init];
        [self.contentView addSubview:_title];
        [_title release];
        self.photoView = [[UIImageView alloc] init]; // 漫画照片
        _photoView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"kuu.png"]];
        [self.contentView addSubview:_photoView];
        
        [_photoView release];
        
        self.author = [[UILabel alloc] init]; // 漫画作者
        [self.contentView addSubview:_author];
        [_author release];
        
        self.updateComics = [[UILabel alloc] init]; // 更新到的章节
        [self.contentView addSubview:_updateComics];
        [_updateComics release];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.read = [[UILabel alloc] init];
        [self.contentView addSubview:_read];
        [_read release];
        
        self.view = [[UIView alloc] initWithFrame:CGRectMake(5, self.contentView.frame.size.height + 90, self.contentView.frame.size.width + 30,0.5)];
        self.view.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_view];
//        self.contentView.backgroundColor =[UIColor redColor];
        self.readButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [_readButton setTitle:@"阅读" forState:UIControlStateNormal];
        [self.contentView addSubview:_readButton];
        
        // 阅读图片
        
        self.readView = [[UIImageView alloc] init];
        [self.contentView addSubview:_readView];
        [_readView release];
        _stars = [[StarsView alloc] initWithFrame:CGRectMake(0.2733 * self.contentView.frame.size.width,0.6071 * self.contentView.frame.size.height,64,12)];

//        _stars.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_stars];

      
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
//    self.frame = CGRectMake(10,0,365,200);

    _title.font = [UIFont boldSystemFontOfSize:17];
    _photoView.frame = CGRectMake(10,5,0.213 * self.contentView.frame.size.width + 10,0.85714 * self.contentView.frame.size.height);
    _title.frame = CGRectMake(0.2533 * self.contentView.frame.size.width + 10,0,0.8 * self.contentView.frame.size.width    ,0.2857 * self.contentView.frame.size.height);
    _author.frame = CGRectMake(0.253333 * self.contentView.frame.size.width + 10,0.2857 * self.contentView.frame.size.height,0.266 * self.contentView.frame.size.width,0.107 * self.contentView.frame.size.height);
    _author.font = [UIFont systemFontOfSize:13];
    _author.textColor = [UIColor darkTextColor];
    
    _author.alpha = 0.7;
    _updateComics.frame = CGRectMake(0.25333 * self.contentView.frame.size.width + 10,0.42857 * self.contentView.frame.size.height,0.266 * self.contentView.frame.size.width, 0.10715 * self.contentView.frame.size.height);
    _updateComics.font = [UIFont systemFontOfSize:13];
    _updateComics.textColor = [UIColor darkGrayColor];
    
    _updateComics.alpha = 0.7;

    self.readButton.frame = CGRectMake(0.7866 * self.contentView.frame.size.width, 0.5 * self.frame.size.height, 0.266 * self.frame.size.width,0.14185 * self.contentView.frame.size.height);
    _readButton.titleLabel.font = [UIFont systemFontOfSize:17];

    
    _readView.frame = CGRectMake(0.893 * self.contentView.frame.size.width,0.25 * self.contentView.frame.size.height,25,25);
    _readView.image = [UIImage imageNamed:@"播放"];
    _stars.frame = CGRectMake(0.2733 * self.contentView.frame.size.width,0.6071 * self.contentView.frame.size.height,64,12);

}
- (void)setComics:(ComicList *)comics
{
    
    if (_comics != comics) {
        [_comics release];
        _comics = [comics retain];
    }
    _title.text = _comics.title;
    NSURL *url = [NSURL URLWithString:comics.cover_url];
    [_photoView setImageWithURL:url];
    _author.text = _comics.artist_name;
    
    
//    _stars.backgroundColor = [UIColor redColor];
    _grade = [_comics.grade integerValue];
    [_stars produceStarView:_grade];

    _updateComics.text = comics.lastup;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)dealloc
{
    [_read release];
    [_photoView release];
    [_readButton release];
    [_title release];
    
    [_updateComics release];
    [_view release];
    [_author release];
    
    [_comics release];
    [super dealloc];
}

@end
